TEventArgs
CSharpTest.Net
EventHandlerForActiveControl<TEventArgs> Class
Members  Example  See Also  Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Delegates Namespace : EventHandlerForActiveControl<TEventArgs> Class

Glossary Item Box

This derivation of EventHandlerForControl<TEventArgs> will simply ignore the call if the control's handle is not at the time the delegate is invoked.

Syntax

Visual Basic (Declaration) 
Public Class EventHandlerForActiveControl(Of TEventArgs As EventArgs) 
   Inherits EventHandlerForControl(Of TEventArgs)
C# 
public class EventHandlerForActiveControl<TEventArgs> : EventHandlerForControl<TEventArgs> 
where TEventArgs: EventArgs

Type Parameters

TEventArgs

Example

Library/Library.Test/TestDelegates.cs

C#Copy Code
EventHandlerForActiveControl<VerifiedReceiptEventArgs> handler;
handler = new EventHandlerForActiveControl<VerifiedReceiptEventArgs>(_form, VerifiedReceipt);
handler = new EventHandlerForActiveControl<VerifiedReceiptEventArgs>(_form, new VerifiedReceiptEventHandler(handler.EventHandler));
VerifiedReceiptEventArgs args = new VerifiedReceiptEventArgs();
_form.Shown += delegate(object s, EventArgs e) { System.Threading.Thread.Sleep(100); _form.Close(); };
_thread.Start();
int total = 0, countOnThread = 0, countOffThread = 0;
try
{
    for (total = 1; total < 1000000; total++)
    {
        handler.EventHandler(null, args.Reset());
        if (args.OnThread)
        {
            Assert.IsTrue(args.Received);
            countOnThread++;
        }
        else
        {
            Assert.IsFalse(args.Received);
            countOffThread++;
        }
        //Assert.IsTrue(args.OnThread);
        //Console.Error.WriteLine("Threaded = {0}", args.OnThread);
        if (_form.IsDisposed)
            break;
    }
    Assert.AreEqual(total, countOnThread + countOffThread);
    Assert.IsTrue(_form.IsDisposed);
    Assert.AreNotEqual(0, countOnThread);
    Assert.AreNotEqual(0, countOffThread);
}
catch (Exception e)
{
    Console.Error.WriteLine(e.ToString());
    throw;
}
finally
{
    _thread.Join();
}
VB.NETCopy Code
Dim handler As EventHandlerForActiveControl(Of VerifiedReceiptEventArgs)
handler = New EventHandlerForActiveControl(Of VerifiedReceiptEventArgs)(_form, VerifiedReceipt)
handler = New EventHandlerForActiveControl(Of VerifiedReceiptEventArgs)(_form, New VerifiedReceiptEventHandler(handler.EventHandler))
Dim args As New VerifiedReceiptEventArgs()
_form.Shown += Function(s As Object, e As EventArgs) Do
    System.Threading.Thread.Sleep(100)
    _form.Close()
End Function
_thread.Start()
Dim total As Integer = 0, countOnThread As Integer = 0, countOffThread As Integer = 0
Try
    total = 1
    While total < 1000000
        handler.EventHandler(Nothing, args.Reset())
        If args.OnThread Then
            Assert.IsTrue(args.Received)
            System.Math.Max(System.Threading.Interlocked.Increment(countOnThread),countOnThread - 1)
        Else
            Assert.IsFalse(args.Received)
            System.Math.Max(System.Threading.Interlocked.Increment(countOffThread),countOffThread - 1)
        End If
        'Assert.IsTrue(args.OnThread);
        'Console.Error.WriteLine("Threaded = {0}", args.OnThread);
        If _form.IsDisposed Then
            Exit While
        End If
        System.Math.Max(System.Threading.Interlocked.Increment(total),total - 1)
    End While
    Assert.AreEqual(total, countOnThread + countOffThread)
    Assert.IsTrue(_form.IsDisposed)
    Assert.AreNotEqual(0, countOnThread)
    Assert.AreNotEqual(0, countOffThread)
Catch e As Exception
    Console.[Error].WriteLine(e.ToString())
    Throw
Finally
    _thread.Join()
End Try

Inheritance Hierarchy

System.Object
   CSharpTest.Net.Delegates.EventHandlerForControl<TEventArgs>
      CSharpTest.Net.Delegates.EventHandlerForActiveControl<TEventArgs>

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys